package com.lntea.jdbc.dbutils;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.ResultSetHandler;

public class QueryRunnerDemo {
	public static void main(String[] args) throws ClassNotFoundException, SQLException {
		ResultSetHandler<User> rsh = new ResultSetHandler<User>() {

			@Override
			public User handle(ResultSet rs) throws SQLException {
				rs.next();
				Long id = rs.getLong("id");
				String name = rs.getString("name");
				Integer age = rs.getInt("age");
				return new User(id, name, age);
			}
		};
		
		QueryRunner queryRunner = new QueryRunner();
		User user = queryRunner.query(ConnectionUtil.getConnection(), "select * from user limit 1", rsh);
		System.out.println(user);
	}
}
